# 字典
# 字典的创建
# 直接赋值
import copy

dict_01 = {'a':1,'b':'2','c':[1,2,3,4],'d':{'e':'1','f':'2','g':'3'}}
# print(dict_01)
# dict()
dict_02 = dict(dict_01)
# print(dict_02)
dict_03 = dict([('a','111'),('b','222'),('c','333')])
# print(dict_03)
dict_04 = dict(aa = '1111',bb = '1122',cc = '1133',dd = '1144')
# print(dict_04)
dict_05 = dict(zip(['a','b','c','d','a'],['112','113','114','115','666']))
# print(dict_05)
# fromkeys
dict_06 = dict.fromkeys(['a','b','ac','ad'])
dict_07 = dict.fromkeys(['aa','ab','ac','ad'],6)
# print(dict_06)
# print(dict_07)

# 字典的访问
# print(dict_06['aa'])
# print(dict_03['a'])
# # print(dict_03['aa']) # aa键不存在，会报错
# print(dict_03.get("aa"))
# print(dict_03.get("aa",2))
# print(dict_03.get("a",2))

# 字典的常用操作
# 修改和添加
# dict_07['aa'] = 7788
# dict_07['af'] = 5566
# print(dict_07)

# 删除操作
# print(dict_06)
# del dict_06['aa']
# print(dict_06)
# dict_06.clear()
# print(dict_06)
# print(dict_07)
# item = dict_07.pop("aa")
# print(dict_07)
# print(item)
# print(dict_02)
# item_01 = dict_02.popitem()
# print(dict_02)
# print(item_01)

# 更新操作
# print(dict_06)
# dict_06.update(dict_05)
# print(dict_06)

# 字典复制
# print(dict_04)
# dict_08 = dict_04
# print(dict_08)
# dict_09 = dict_04.copy()
# print(dict_09)
# dict_10 = copy.deepcopy(dict_04)
# print(dict_10)

# 字典的遍历
print(dict_04.items())
print(dict_04.keys())
print(dict_04.values())
